package com.ruoyi.project.student.controller;

import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.student.domain.Student;
import com.ruoyi.project.student.domain.param.StudentParam;
import com.ruoyi.project.student.domain.vo.StudentListvo;
import com.ruoyi.project.student.service.StudentService;
import com.ruoyi.project.system.domain.SysConfig;
import com.ruoyi.project.system.service.ISysConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.ruoyi.common.utils.PageUtils.startPage;

@RestController
@RequestMapping("/student")
public class StudentController extends BaseController {
    @Autowired
    private StudentService studentService;

    /**
     * 获取参数配置列表
     */
    @PreAuthorize("@ss.hasPermi('student:list')")
    @GetMapping("/list")
    public TableDataInfo list(StudentParam param)
    {
        startPage();
        List<StudentListvo> list = studentService.selectStudentList(param);
        return getDataTable(list);
    }
    @PreAuthorize("@ss.hasPermi('student:add')")
    @PostMapping("/add")
    public AjaxResult add(@Validated @RequestBody Student student)
    {
        boolean Issuccss;
        try {
//            i = studentService.insertStudent(student);
            Issuccss = studentService.save(student);
        } catch (Exception e) {
           return error(e.getMessage());
        }
        return success(Issuccss);
    }
    @PreAuthorize("@ss.hasPermi('student:edit')")
    @PostMapping("/edit")
    public AjaxResult edit(@Validated @RequestBody Student student) throws Exception {
        try{
        Boolean Issuccess=studentService.updateById(student);
        return success(Issuccess);
        }catch (Exception e){
            return error(e.getMessage());
        }
    }
    @PreAuthorize("@ss.hasPermi('student:delete')")
    @PostMapping("/delete")
    public AjaxResult delete(@Validated @RequestBody Student student) throws Exception {
       try{
       Boolean Issuccess=studentService.removeById(student);
       return success(Issuccess);
       }catch (Exception e){
           return error(e.getMessage());
       }
    }


}
